package cn.zte.com.train.hiber8train;


import java.util.UUID;

import org.hibernate.Session;
import org.hibernate.SessionFactory;
import org.hibernate.Transaction;
import org.hibernate.boot.MetadataSources;
import org.hibernate.boot.registry.StandardServiceRegistryBuilder;
import org.hibernate.boot.spi.MetadataImplementor;
import org.hibernate.cfg.Configuration;
import org.hibernate.id.UUIDGenerator;
import org.hibernate.service.ServiceRegistry;

public class HiberCrudTest {

	public static void main(String[] args) {
		
//		Configuration configuration = new Configuration();
//		configuration.configure("");
//		configuration.buildSessionFactory();
		// TODO Auto-generated method stub
		ServiceRegistry serviceRegistry = new StandardServiceRegistryBuilder().configure().build();
		MetadataImplementor metadata = (MetadataImplementor) new MetadataSources( serviceRegistry ).buildMetadata();
		SessionFactory factory = metadata.buildSessionFactory();
//		MetadataSources meta = new MetadataSources( serviceRegistry );
//		Configuration config = new Configuration(meta);
//		SessionFactory factory = config.buildSessionFactory();
		Session session = factory.openSession();
		//瞬时态
		Users user = new Users();
		user.setGentle("1");
		user.setPassword("guochangchun");
		user.setUsername("guochun2222");
		Transaction trans = session.getTransaction();
		trans.begin();
		//持久态
		session.save(user);
		session.delete(user);
		//游离态->持久态
		//session.update(user);
		trans.commit();
		session.close();
	}

}
